package com.example.yiwei.crm.json;

import com.example.yiwei.crm.entity.LogEntity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DHN on 2017/4/28.
 */

public class LogJson {
    public static List<LogEntity> get(String result){
        List<LogEntity> list ;
        LogEntity logEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                logEntity = new LogEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("CID01")){
                    logEntity.setPeople(json.getString("CID01"));
                }
                if (json.has("KCA02")){
                    logEntity.setWork(json.getString("KCA02"));
                }
                if (json.has("KCA03")){
                    logEntity.setSubstance(json.getString("KCA03"));
                }
                if (json.has("CTS01L")){
                    logEntity.setTime(json.getString("CTS01L"));
                }
                list.add(logEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
}
